import concurrent.futures
import subprocess
import os

def download_file(url, directory):
    try:
        subprocess.run(['wget', url, '-P', directory], check=True)
        print(f"Successfully downloaded: {url}")
    except subprocess.CalledProcessError:
        print(f"Failed to download: {url}")

def main():
    urls = [
        "https://hf-mirror.com/IndexTeam/IndexTTS-1.5/resolve/main/config.yaml",
        "https://hf-mirror.com/IndexTeam/IndexTTS-1.5/resolve/main/bigvgan_discriminator.pth",
        "https://hf-mirror.com/IndexTeam/IndexTTS-1.5/resolve/main/bigvgan_generator.pth",
        "https://hf-mirror.com/IndexTeam/IndexTTS-1.5/resolve/main/bpe.model",
        "https://hf-mirror.com/IndexTeam/IndexTTS-1.5/resolve/main/dvae.pth",
        "https://hf-mirror.com/IndexTeam/IndexTTS-1.5/resolve/main/gpt.pth",
        "https://hf-mirror.com/IndexTeam/IndexTTS-1.5/resolve/main/unigram_12000.vocab"
    ]

    directory = "checkpoints"
    
    # 创建目录（如果不存在）
    os.makedirs(directory, exist_ok=True)

    # 使用线程池执行下载
    with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
        futures = [executor.submit(download_file, url, directory) for url in urls]
        concurrent.futures.wait(futures)

if __name__ == "__main__":
    main()